package KK.WindowSkin
{
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	public class TitleSheet implements ISkin
	{
		static public const Source:int=0;
		static public const Target:int=1;
		
		
		private var size:Point;
		private var _area:Vector.<Rectangle>;
		public function TitleSheet()
		{
			//TODO: implement function
			init();
		}
		
		private function init():void{
			
		}
		
		
		/**
		 * 计算 
		 * @param width
		 * @param height
		 * 
		 */
		public function calc(width:Number,height:Number):void{
			
			size=new Point();
			size.x=width;
			size.y=height;
			
			
			
			_area=new Vector.<Rectangle>(3,true);
			
			var targetWidth:Number=size.x/3;
			
			var i:int=0;
			var len:int=_area.length;
			var rect:Rectangle;
			while(i<len){
				
				rect=new Rectangle();
				
				rect.width=targetWidth;
				rect.height=size.y;
				rect.x=i*targetWidth;
				_area[i]=rect;
				i++;
			}
		}
		
		/**
		 * 计算目标区域  
		 * @return 
		 * 
		 */
		public function calcTarget(width:Number,height:Number):Vector.<Vector.<Rectangle>>{
			calc(size.x,size.y);
			width-=10;
			var result:Vector.<Vector.<Rectangle>>=new Vector.<Vector.<Rectangle>>(2,true);
			result[Source]=_area;
			result[Target]=new Vector.<Rectangle>;
			
			var percentWidth:Number=width/3;
			
			var rect:Rectangle;
			
			var i:int=0;
			var len:int=3;
			while(i<len){
				rect=new Rectangle();
				
				rect.width=_area[i].width>width?percentWidth:_area[i].width;
				
				if(_area[i].width>width||_area[i].width>percentWidth){
					rect.width=percentWidth;
					_area[i].width=percentWidth;
					if((i+1)%3==0){
						_area[i].x=size.x-percentWidth;
					}else{ 
						
					}
				}else{
					if((i+1)%2==0){
						rect.width=width-_area[i-1].width*2;
					}else{
						rect.width=_area[i].width;
					}
				}
				
				
				
				
				if(i-1>=0){
					rect.x=result[Target][i-1].x+result[Target][i-1].width+0;
					
				}else{
					rect.x=0;
				}
				rect.y=0;
				rect.height=_area[i].height;
				result[Target][i]=rect;
				i++;
			}
			
			
			
			
			/*
			var i:int=0;
			var len:int=3;
			while(i<len){
				
				
				var percentWidth:Number=width/3;
				var targetWidth:Number=0;
				
				result[Target][i]=(_area[i].clone());
				switch(true){
					case (i+1)%5==0:
					case (i+1)%2==0: 
						targetWidth=width-result[Source][i-1].width;
						result[Target][i].width=width>targetWidth?targetWidth:percentWidth;
						result[Target][i].x=i-1>=0?result[Target][i-1].x+result[Target][i-1].width:0;
						
						break; 
					default:
						result[Target][i].width=width>result[Source][i].width?result[Source][i].width:percentWidth;
						result[Target][i].x=i-1>=0?result[Target][i-1].x+result[Target][i-1].width:0;
						break;
				} 
				result[Target][i].y=10;
				result[Target][i].x+=10;
				LogInfo(result[Target][i]);
				i++;
			}
//			result[Target][2].width=result[Source][2].width;
			result[Target][2].x=width-result[Source][2].width;
//			_area[2].width=result[Target][2].width; 
			*/
			return result;
		}
		
		public function get Sudoku():Vector.<Rectangle>
		{
			//TODO: implement function
			return _area;
		}
	}
}